package com.olc.railing.utils;

import android.hardware.Camera;
import android.os.Build;
import android.util.Log;

public class CameraUtils {
    private static final String TAG = "CameraUtils";
    private static boolean checkCameraFacing(final int facing) {
        MyLog.d(TAG,"摄像头 FLAG "+facing);
        if (getSdkVersion() < Build.VERSION_CODES.GINGERBREAD) {
            return false;
        }
        final int cameraCount = Camera.getNumberOfCameras();
        MyLog.d(TAG,"摄像头  COUNT "+cameraCount);
        Camera.CameraInfo info = new Camera.CameraInfo();
        for (int i = 0; i < cameraCount; i++) {
            Camera.getCameraInfo(i, info);
            MyLog.d(TAG,"摄像头  INFO "+info.facing);
            if (facing == info.facing) {
                return true;
            }
        }
        return false;
    }
    /**
     * 检查设备是否有摄像头
     * @return
     */
    public static boolean hasCamera() {
        boolean back = hasBackFacingCamera();
        boolean front = hasFrontFacingCamera();
        Log.d("11111111",back+"  "+front);
        return  back|| front;
    }


    /**检查设备是否有后置摄像头
     * @return
     */
    public static boolean hasBackFacingCamera() {
        final int CAMERA_FACING_BACK = 0;
        return checkCameraFacing(CAMERA_FACING_BACK);
    }

    /**检查设备是否有前置摄像头
     * @return
     */
    public static boolean hasFrontFacingCamera() {
        final int CAMERA_FACING_BACK = 1;
        return checkCameraFacing(CAMERA_FACING_BACK);
    }

    public static int getSdkVersion() {
        return Build.VERSION.SDK_INT;
    }
}
